package com.example.tests.logic;

import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;

public class AlertHelper {
	private boolean acceptNextAlert = true;
	private WebDriver driver;
	public AlertHelper(WebDriver driver) {
		this.driver = driver; 
	}
	public void closeAlert() {
		driver.switchTo().alert().accept();
	}
	public boolean isAlertTextMatches(String text) {
		return closeAlertAndGetItsText().matches(text);
	}
	
	public String closeAlertAndGetItsText() {
	    Alert alert = driver.switchTo().alert();
		if (acceptNextAlert) {
			alert.accept();
	      } else {
	        alert.dismiss();
	      }
	      return alert.getText();
	}
}
